package com.atguigu.lease.admin.controller;

import com.atguigu.lease.admin.service.FacilityInfoService;
import com.atguigu.lease.enums.ItemType;
import com.atguigu.lease.pojo.FacilityInfo;
import com.atguigu.lease.result.Result;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/facility")
@RestController()
public class FacilityInfoController {
    @Autowired
    private FacilityInfoService facilityInfoService;

    @GetMapping("/list")
    public Result<List<FacilityInfo>> list(@RequestParam(value = "type",required = false) ItemType type) {
        List<FacilityInfo> list = facilityInfoService.list(Wrappers.lambdaQuery(FacilityInfo.class).eq(type != null, FacilityInfo::getType, type));
        return Result.success(list);
    }

    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody FacilityInfo facilityInfo) {
        facilityInfoService.saveOrUpdate(facilityInfo);
        return Result.success();
    }

    @DeleteMapping("/deleteById")
    public Result deleteFacilityInfoById(@RequestParam(value = "id") Long id) {
        facilityInfoService.removeById(id);
        return Result.success();
    }
}
